// pages/my/daizhuce/daizhuce.js
var app = getApp();
var $ = app.globalData;
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		daiinfo:{name:'',phone:'',yqcode:''},
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		var daiinfo = this.data.daiinfo
		daiinfo['yqcode'] = wx.getStorageSync('userinfo').loginname
		this.setData({
			daiinfo:daiinfo,
			userinfo:wx.getStorageSync('userinfo')
		})
	},
	// 姓名
	name:function(e){
		var daiinfo = this.data.daiinfo
		daiinfo['name'] = e.detail.value
		this.setData({
			daiinfo:daiinfo
		})
	},
	// 手机号
	phone:function(e){
		var daiinfo = this.data.daiinfo
		daiinfo['phone'] = e.detail.value
		this.setData({
			daiinfo:daiinfo
		})
	},
	// 邀请码
	yqcode:function(e){
		var daiinfo = this.data.daiinfo
		daiinfo['yqcode'] = e.detail.value
		this.setData({
			daiinfo:daiinfo
		})
	},
	// 下一步
	logout:function(){
		var that = this
		if(that.data.daiinfo['name'] == ""){
			wx.showToast({
				icon:'none',
				title: "请输入姓名",
				duration: 3000,
			})
		}else if(that.data.daiinfo['phone'] == "" || that.data.daiinfo['phone'][0] != "1" || that.data.daiinfo['phone'].length != 11){
			wx.showToast({
				icon:'none',
				title: "请输入正确的手机号",
				duration: 3000,
			})
		}else if(that.data.daiinfo['yqcode'] == "" ){
			wx.showToast({
				icon:'none',
				title: "请输入邀请码",
				duration: 3000,
			})
		}else{
			// 保存注册信息到全局变量跳转至下一步
			$.daizhuce = that.data.daiinfo
			$.shoptype = 3
			wx.navigateTo({
				url:"/pages/shopping/shoplist/shoplist?tabone=-1&tabtwo=-1&daizhuce=true"
			})
		}
	},
	// 分享转发
		onShareAppMessage: function() {
			var userinfo = wx.getStorageSync('userinfo')
			return {
				title: '优悦购生活管家',
				path: '/pages/index/index?userid='+userinfo.loginname,
				success: (res) => {
					console.log("转发成功", res);
				},
				fail: (res) => {
					console.log("转发失败", res);
				}
			}
		}
})
